package study.web.service.jaxws.service.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.ws.BindingType;

import study.web.service.jaxws.pojo.Weather;
import study.web.service.jaxws.service.IWeatherService;

/**  
* @Name: WeatherServiceImpl
* @Description: 天气信息查询服务接口实现类
* @Author: 李超
* @Create Date: 2017-01-07
*/
@WebService(targetNamespace="http://impl.jaxws.service.web.study",
			serviceName="WeatherService12",
			portName="WeatherServiceSoap12",
			name="WeatherInterface12")
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
public class WeatherServiceImpl implements IWeatherService {

	/**  
	* @Name: queryWeatherByCityName（方法的名称）
	* @Description: 根据城市名称，查询未来三天的天气信息（方法的描述）
	* @Author: 李超（作者）
	* @Version: V1.00 （版本号）
	* @Create Date: 2017-01-07 （创建日期）
	* @Parameters: String cityName 城市名称（方法的入参，如果没有，填写为“无”）
	* @Return: List<Weather> 返回城市对象集合（返回值，如果没有，填写为“无”）
	*/
	@WebMethod(operationName="queryWeatherByCityName", exclude=false)
	public @WebResult(name="weatherList")List<Weather> queryWeatherByCityName(@WebParam(name="cityName")String cityName) {
		System.out.println("from client ... " + cityName);
		//模拟生成三天的天气信息数据
		List<Weather> list = new ArrayList<>() ;
		Calendar calendar = Calendar.getInstance() ;
		int day = calendar.get(Calendar.DATE) ;
		Weather weather01 = new Weather("晴朗", calendar.getTime(), 32, 21) ;
		calendar.add(Calendar.DATE, day+1) ;
		Weather weather02 = new Weather("多云", calendar.getTime(), 24, 11) ;
		calendar.add(Calendar.DATE, day+1) ;
		Weather weather03 = new Weather("阴天", calendar.getTime(), 21, 10) ;
		list.add(weather01) ;
		list.add(weather02) ;
		list.add(weather03) ;
		System.out.println("to client ... ");
		for (Weather weather : list) {
			System.out.println(weather);
		}
		//将天气信息返回给客户端
		return list;
	}

}
